home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / GNU_Backgammon / gnubg-MAIN-20110822-setup.exe / {app} / batch_win.py next >
Encoding:
Python Source  |  2007-07-02  |  2.1 KB  |  58 lines

  1. #
  2. # batch_win.py -- batch import and analysis of multiple files using gnubg
  3. #
  4. # by Oystein Johansen <oystein@gnubg.org>, 2004
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of version 3 or later of the GNU General Public License as
  8. # published by the Free Software Foundation.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. #
  19. # $Id: batch_win.py,v 1.2 2007/07/02 12:50:13 ace Exp $
  20.  
  21. # This file is inspired of the batch.py file of Jon Kinsey. The code
  22. # contains MS-Windows specific code and will therefore only work on MS-Windows
  23. # together with GNU Backgammon and Python.
  24.  
  25. import win32ui, win32con
  26.  
  27. # file extensions, names and gnubg import commands
  28.  
  29. extensions = ['mat', 'pos', 'sgg', 'tmg', 'txt']
  30. extTypes = ['.mat', '.pos', 'Games grid', 'True money game', 'Snowie text']
  31. extCmds = ['mat', 'pos', 'sgg', 'tmg', 'snowietxt']
  32.  
  33. def BatchAnalyze(filelist):
  34.     for file in filelist:
  35.         dot = file.rfind('.')
  36.         if dot != -1:
  37.             ext = file[dot + 1 : ].lower()
  38.             if ext in extensions:
  39.                 AnalyzeFile(file, extensions.index(ext))
  40.                 
  41. def GetFiles():
  42.     import win32ui, win32con
  43.     filedialog = win32ui.CreateFileDialog(1,"", "", win32con.OFN_ALLOWMULTISELECT | win32con.OFN_HIDEREADONLY)
  44.     filedialog.SetOFNTitle("Select files to analyse")
  45.     filedialog.DoModal()
  46.     
  47.     return filedialog.GetPathNames()
  48.  
  49. def AnalyzeFile( file, type):
  50.     "Run commands to analyze file in gnubg"
  51.     gnubg.command('import ' + extCmds[type] + ' "' + file + '"')
  52.     gnubg.command('analyze match')
  53.     file = file[:-len(extensions[type])] + "sgf"
  54.     gnubg.command('save match "' + file + '"')
  55.  
  56. files = GetFiles()
  57. BatchAnalyze(files)
  58.